<template>
  <div class="admin">
    <!-- hello -->

    <!-- 左侧 -->
    <div class="menu" v-bind:style="{ width: menuWidth }">
      <el-menu
        default-active="1-4"
        class="el-menu-vertical-demo"
        @open="handleOpen"
        @close="handleClose"
        :collapse="isHiddenMenu"
        background-color="#263445"
        text-color="rgb(191, 203, 217)"
        :collapse-transition="false"
      >
        <el-submenu
          v-for="(item, index) in meuns"
          :index="(index + 1).toString()"
          :key="index"
        >
          <template slot="title">
            <i class="icon iconfont icon-xueyuan2"></i>
            <span slot="title">{{ item.auth_name }}</span>
          </template>
          <!-- <el-menu-item-group> -->
          <el-menu-item
            :index="index + 1 + '-' + (index2 + 1)"
            class="icon iconfont icon-xueyuanguanli"
            v-for="(item2, index2) in item.children"
            :key="index2"
          >
            <router-link :to="item2.url">
              {{ item2.auth_name }}
            </router-link>
          </el-menu-item>
          <!-- </el-menu-item-group> -->
        </el-submenu>
      </el-menu>
    </div>
    <!-- /左侧 -->
    <!-- 右侧 -->
    <div class="main">
      <div class="top">
        <div class="l">
          <div class="btn" @click="handleMenu">
            <span class="iconfont icon-caidan">
              <i class="icon iconfont icon-xueyuanguanli"></i>
            </span>
          </div>
          <div class="breadcrumb">
            <Breadcrumb :name1="name1" :name2="name2"></Breadcrumb>
          </div>
        </div>
        <div class="r">
          <p>{{ uname }} {{ roleName }}</p>
        </div>
      </div>
      <div class="content">
        <!-- 显示当前组件子级 -->
        <!-- name="自己写c3" -->
        <transition appear enter-active-class="animated slideInRight">
          <router-view></router-view>
        </transition>
      </div>
    </div>
    <!-- /右侧 -->
  </div>
</template>

<script>
// import breadcrumb from "../../components/Breadcrumb"
// import { mapState } from "vuex"
import Breadcrumb from "../components/Breadcrumb";
export default {
  //面包屑的处理
  components: {
    Breadcrumb
  },
  created() {
    // console.log(this.$router)//这是整个路由实例 打印出来里面会有.app属性  .app里面会有._route属性
    // console.log(this.$router.app._route)
    this.name1 = this.$router.app._route.meta.name1;
    this.name2 = this.$router.app._route.meta.name2;
  },
  watch: {
    $route(newData, oldData) {
      // console.log(newData);
      this.name1 = newData.meta.name1;
      this.name2 = newData.meta.name2;
    }
  },

  // //获取unmae,token,rolename的数据
  // computed: {
  //     ...mapState({
  //         uname: state => state.users.uname,
  //         token: state => state.users.token,
  //         roleName: state => state.users.roleName
  //     })
  // },
  data() {
    return {
      meuns: localStorage.getItem("meuns")
        ? JSON.parse(localStorage.getItem("meuns"))
        : [],
      // 是否隐藏菜单
      isHiddenMenu: false,
      // 菜单宽度
      menuWidth: "200px",
      name1: "后台首页",
      name2: "欢迎页",
      uname: localStorage.getItem("uname") || "",
      roleName: localStorage.getItem("roleName") || ""
    };
  },
  methods: {
    handleMenu() {
      this.isHiddenMenu = !this.isHiddenMenu;
      this.menuWidth = this.isHiddenMenu ? "64px" : "200px";
    },
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    }
  }
};
</script>

<style lang="scss" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
// admin
.admin {
  width: 100%;
  height: 100%;
  display: flex;
  overflow: hidden;

  // menu
  .menu {
    a {
      text-decoration: none;
      color: #fff;
    }
    .el-menu {
      width: 100%;
      height: 100%;
    }
    width: 200px;
    height: 100%;
    background: #263445;
    transition: width 0.28s;

    ul {
      border: none;
    }
  }

  // main
  .main {
    flex: 1; // 使用剩余空间 前提父得弹性盒布局
    background: white;
    overflow-y: scroll;

    // top
    .top {
      width: 100%;
      height: 50px;
      margin-bottom: 30px;
      background: grey;
      box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
      display: flex;
      justify-content: space-between;

      .l {
        width: 300px;
        height: 100%;
        background: grey;
        overflow: hidden;
        .btn {
          width: 50px;
          height: 50px;
          text-align: center;
          line-height: 50px;
          float: left;
          .icon iconfont icon-xueyuanguanli {
            width: 18px;
            height: 18px;
          }
        }

        .btn:hover {
          background: #ccc;
          cursor: pointer;
        }
        .breadcrumb {
          width: 250px;
          height: 50px;
          line-height: 50px;
          background: grey;
          float: left;
        }
      }
      .r {
        width: 240px;
        height: 100%;
        background: grey;
        p {
          font-size: 18px;
          position: absolute;
          margin-top: 20px;
        }
      }
    }
    // content
    .content {
      width: 96%;
      min-height: 100px;
      /* height: 100%; */
      margin: auto;
      background: white;
      /* margin-top: 1000px; */
    }
  }
}
</style>
